/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.dwusoft.info.util  
 */
package com.apache.tools;

import java.util.HashMap;

/**
 * description:  自定义信息发布转换Map
 * @author dwusoft 创建时间：2015-11-12  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
@SuppressWarnings("serial")
public class DataMap<V> extends HashMap<String, V> {

	public V put(String key, V value) {
		String pojoName = "";
		String propertyName = key;
		if (key.contains("@")) {
			String arrayStr[] = key.split("@");
			pojoName = arrayStr[0];
			propertyName = arrayStr[1];
		}
		return super.put(pojoName + "." + toCamelNamed(propertyName), value);
	}

	public void putAll(java.util.Map<? extends String, ? extends V> map) {
		super.putAll(map);
	}

	// not @Override because that would require the key parameter to be of type Object
	public V get(String key) {
		return super.get(key);
	}

	/**
	 * 属性值生成,符合骆驼命名
	 * @param str
	 * @return
	 */
	private String toCamelNamed(String str) {
		String names[] = str.toLowerCase().split("_");
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < names.length; i++) {
			if (i == 0) {
				sb.append(names[i].toLowerCase());
			} else {
				sb.append(names[i].substring(0, 1).toUpperCase() + names[i].substring(1).toLowerCase());
			}
		}
		return sb.toString();
	}
}
